#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os
import requests

base_path = "/download"
def storage_local(keyword, images):

    # 根据搜索关键字创建子文件夹，用于放置该关键字搜索得到的图片
    dict_folder_path = "%s/%s"%(base_path, keyword)
    if not os.path.exists(dict_folder_path):
        os.makedirs(dict_folder_path)

    for image in images:
        if image:
            # build 保存图片的全路径名
            dict_image_path = "%s/%s_%s.%s"%(dict_folder_path, keyword, images.index(image), image.split(".")[-1])

            # 远程请求图片，获取图片的二进制内容，写入文件
            result = requests.get(image).content
            with open(dict_image_path, "wb") as f:
                f.write(result)

if __name__ == '__main__':
    storage_local("hujiang", [])